/*
 Copyright (c) 2010 Konstantin Denerz
 Licensed under the MIT license (MIT-LICENSE.txt):
 http://www.opensource.org/licenses/mit-license.php
 */
var withException = {
    type: "jqtools.exception"
};

test("test tools function", function(){
    ok($().tools, "tools function should be defined");
    
    tryIt(function(){
        $().tools(null);
    }, "use null as parameter", withException);
    
    tryIt(function(){
        $().tools(function(){
        });
    }, "use function as parameter", withException);
    
    tryIt(function(){
        $().tools([]);
    }, "use an empty array as parameter", withException);
    
    tryIt(function(){
        $().tools([{
            id: ""
        }]);
    }, "use an array with empty JSON as parameter");
    
    tryIt(function(){
        $().tools([""]);
    }, "use an array with empty string as parameter", withException);
    
});



test("test provided functions", function(){

    var defaultToolbar = [{
        id: "save"
    }, {
        id: "restore"
    }];
    
    var suffix = " function should be defined";
    ok($().tools(defaultToolbar).use, "use" + suffix);
    /*  ok($().tools(defaultToolbar).update, "update" + suffix);
     ok($().tools(defaultToolbar).activate, "activate" + suffix);
     ok($().tools(defaultToolbar).deactivate, "deactivate" + suffix);
     ok($().tools(defaultToolbar).config, "config" + suffix);*/
})

var createDefaultToolbar = function(toolCount){
    var toolbar = [];
    for (var i = 0; i < toolCount; i++) {
        toolbar.push({
            id: i + "Tool",
            icon: "res/tool.png"
        })
    }
    return toolbar;
};

test("test use function", function(){
    // define
    var toolCount = 10;
    // process
    $("#toolbar").tools(createDefaultToolbar(toolCount)).use().use();
    // test
    equals($("#toolbar").find(".tool").length, toolCount, "toolbar should contains " + toolCount + " elements");
});


